home *** CD-ROM | disk | FTP | other *** search
/ PCNet 2006 April / PCnet 2006-06.4.iso / shareware / nmsetup.exe / WebServer / web / _login_js.php < prev    next >
Encoding:
PHP Script  |  2006-05-01  |  10.3 KB  |  267 lines

  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////////
  3. // <!--Copyright (c) 2005 Pure Networks Inc.  All rights reserved.-->
  4. ////////////////////////////////////////////////////////////////////////////////
  5. //
  6. // Build: 3.0.6121.0 (Stable)
  7. // $Revision: #1 $
  8. //
  9. ?>
  10. <script type="text/javascript">
  11.     function authenticate_and_login(session_id)
  12.     {
  13.         if (document.loginform.submitted.value != "yes")
  14.         {
  15.             // set submitted hidden field so we don't submit twice
  16.             document.loginform.submitted.value = "yes";
  17.             // Calculate the hash from the "password" + "session id"
  18.             // Send this hash down to the server
  19.             document.loginform.hash.value = hexMD5(document.loginform.login.value + session_id);
  20.             document.loginform.login.value = 'Logging In......';
  21.             document.getElementById('Continue').focus();
  22.             document.getElementById('Continue').className = "LoginButton ButtonDisabled";
  23.             document.getElementById('spHide').style.display = "none";
  24.             document.getElementById('spWarn').style.display = "block";
  25.             document.getElementById('spWarn').style.visibility = "visible";
  26.         }        
  27.     }
  28.     
  29.     function submitViaButton(session_id)
  30.     {
  31.         authenticate_and_login(session_id);
  32.         document.loginform.submit();
  33.     }
  34.  
  35.     /*
  36.     * Portions derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm.
  37.     * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
  38.     * rights reserved.
  39.     *  
  40.     * License to copy and use this software is granted provided that it
  41.     * is identified as the "RSA Data Security, Inc. MD5 Message-Digest
  42.     * Algorithm" in all material mentioning or referencing this software
  43.     * or this function.
  44.     *  
  45.     * License is also granted to make and use derivative works provided
  46.     * that such works are identified as "derived from the RSA Data
  47.     * Security, Inc. MD5 Message-Digest Algorithm" in all material
  48.     * mentioning or referencing the derived work.
  49.     *  
  50.     * RSA Data Security, Inc. makes no representations concerning either
  51.     * the merchantability of this software or the suitability of this
  52.     * software for any particular purpose. It is provided "as is"
  53.     * without express or implied warranty of any kind.
  54.     *  
  55.     * These notices must be retained in any copies of any part of this
  56.     * documentation and/or software.
  57.     */
  58.  
  59.     /*
  60.     * Add integers, wrapping at 2^32. This uses 16-bit operations internally
  61.     * to work around bugs in some JS interpreters.
  62.     */
  63.     function safe_add(x, y)
  64.     {
  65.         var lsw = (x & 0xFFFF) + (y & 0xFFFF)
  66.         var msw = (x >> 16) + (y >> 16) + (lsw >> 16)
  67.         return (msw << 16) | (lsw & 0xFFFF)
  68.     }
  69.  
  70.     /*
  71.     * Bitwise rotate a 32-bit number to the left.
  72.     */
  73.     function rol(num, cnt)
  74.     {
  75.         return (num << cnt) | (num >>> (32 - cnt))
  76.     }
  77.  
  78.     /*
  79.     * These functions implement the four basic operations the algorithm uses.
  80.     */
  81.     function cmn(q, a, b, x, s, t)
  82.     {
  83.         return safe_add(rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b)
  84.     }
  85.     function ff(a, b, c, d, x, s, t)
  86.     {
  87.         return cmn((b & c) | ((~b) & d), a, b, x, s, t)
  88.     }
  89.     function gg(a, b, c, d, x, s, t)
  90.     {
  91.         return cmn((b & d) | (c & (~d)), a, b, x, s, t)
  92.     }
  93.     function hh(a, b, c, d, x, s, t)
  94.     {
  95.         return cmn(b ^ c ^ d, a, b, x, s, t)
  96.     }
  97.     function ii(a, b, c, d, x, s, t)
  98.     {
  99.         return cmn(c ^ (b | (~d)), a, b, x, s, t)
  100.     }
  101.  
  102.     /*
  103.     * Calculate the MD5 of an array of little-endian words, producing an array
  104.     * of little-endian words.
  105.     */
  106.     function coreMD5(x)
  107.     {
  108.         var a =  1732584193
  109.         var b = -271733879
  110.         var c = -1732584194
  111.         var d =  271733878
  112.     
  113.         for(i = 0; i < x.length; i += 16)
  114.         {
  115.             var olda = a
  116.             var oldb = b
  117.             var oldc = c
  118.             var oldd = d
  119.  
  120.             a = ff(a, b, c, d, x[i+ 0], 7 , -680876936)
  121.             d = ff(d, a, b, c, x[i+ 1], 12, -389564586)
  122.             c = ff(c, d, a, b, x[i+ 2], 17,  606105819)
  123.             b = ff(b, c, d, a, x[i+ 3], 22, -1044525330)
  124.             a = ff(a, b, c, d, x[i+ 4], 7 , -176418897)
  125.             d = ff(d, a, b, c, x[i+ 5], 12,  1200080426)
  126.             c = ff(c, d, a, b, x[i+ 6], 17, -1473231341)
  127.             b = ff(b, c, d, a, x[i+ 7], 22, -45705983)
  128.             a = ff(a, b, c, d, x[i+ 8], 7 ,  1770035416)
  129.             d = ff(d, a, b, c, x[i+ 9], 12, -1958414417)
  130.             c = ff(c, d, a, b, x[i+10], 17, -42063)
  131.             b = ff(b, c, d, a, x[i+11], 22, -1990404162)
  132.             a = ff(a, b, c, d, x[i+12], 7 ,  1804603682)
  133.             d = ff(d, a, b, c, x[i+13], 12, -40341101)
  134.             c = ff(c, d, a, b, x[i+14], 17, -1502002290)
  135.             b = ff(b, c, d, a, x[i+15], 22,  1236535329)
  136.  
  137.             a = gg(a, b, c, d, x[i+ 1], 5 , -165796510)
  138.             d = gg(d, a, b, c, x[i+ 6], 9 , -1069501632)
  139.             c = gg(c, d, a, b, x[i+11], 14,  643717713)
  140.             b = gg(b, c, d, a, x[i+ 0], 20, -373897302)
  141.             a = gg(a, b, c, d, x[i+ 5], 5 , -701558691)
  142.             d = gg(d, a, b, c, x[i+10], 9 ,  38016083)
  143.             c = gg(c, d, a, b, x[i+15], 14, -660478335)
  144.             b = gg(b, c, d, a, x[i+ 4], 20, -405537848)
  145.             a = gg(a, b, c, d, x[i+ 9], 5 ,  568446438)
  146.             d = gg(d, a, b, c, x[i+14], 9 , -1019803690)
  147.             c = gg(c, d, a, b, x[i+ 3], 14, -187363961)
  148.             b = gg(b, c, d, a, x[i+ 8], 20,  1163531501)
  149.             a = gg(a, b, c, d, x[i+13], 5 , -1444681467)
  150.             d = gg(d, a, b, c, x[i+ 2], 9 , -51403784)
  151.             c = gg(c, d, a, b, x[i+ 7], 14,  1735328473)
  152.             b = gg(b, c, d, a, x[i+12], 20, -1926607734)
  153.  
  154.             a = hh(a, b, c, d, x[i+ 5], 4 , -378558)
  155.             d = hh(d, a, b, c, x[i+ 8], 11, -2022574463)
  156.             c = hh(c, d, a, b, x[i+11], 16,  1839030562)
  157.             b = hh(b, c, d, a, x[i+14], 23, -35309556)
  158.             a = hh(a, b, c, d, x[i+ 1], 4 , -1530992060)
  159.             d = hh(d, a, b, c, x[i+ 4], 11,  1272893353)
  160.             c = hh(c, d, a, b, x[i+ 7], 16, -155497632)
  161.             b = hh(b, c, d, a, x[i+10], 23, -1094730640)
  162.             a = hh(a, b, c, d, x[i+13], 4 ,  681279174)
  163.             d = hh(d, a, b, c, x[i+ 0], 11, -358537222)
  164.             c = hh(c, d, a, b, x[i+ 3], 16, -722521979)
  165.             b = hh(b, c, d, a, x[i+ 6], 23,  76029189)
  166.             a = hh(a, b, c, d, x[i+ 9], 4 , -640364487)
  167.             d = hh(d, a, b, c, x[i+12], 11, -421815835)
  168.             c = hh(c, d, a, b, x[i+15], 16,  530742520)
  169.             b = hh(b, c, d, a, x[i+ 2], 23, -995338651)
  170.  
  171.             a = ii(a, b, c, d, x[i+ 0], 6 , -198630844)
  172.             d = ii(d, a, b, c, x[i+ 7], 10,  1126891415)
  173.             c = ii(c, d, a, b, x[i+14], 15, -1416354905)
  174.             b = ii(b, c, d, a, x[i+ 5], 21, -57434055)
  175.             a = ii(a, b, c, d, x[i+12], 6 ,  1700485571)
  176.             d = ii(d, a, b, c, x[i+ 3], 10, -1894986606)
  177.             c = ii(c, d, a, b, x[i+10], 15, -1051523)
  178.             b = ii(b, c, d, a, x[i+ 1], 21, -2054922799)
  179.             a = ii(a, b, c, d, x[i+ 8], 6 ,  1873313359)
  180.             d = ii(d, a, b, c, x[i+15], 10, -30611744)
  181.             c = ii(c, d, a, b, x[i+ 6], 15, -1560198380)
  182.             b = ii(b, c, d, a, x[i+13], 21,  1309151649)
  183.             a = ii(a, b, c, d, x[i+ 4], 6 , -145523070)
  184.             d = ii(d, a, b, c, x[i+11], 10, -1120210379)
  185.             c = ii(c, d, a, b, x[i+ 2], 15,  718787259)
  186.             b = ii(b, c, d, a, x[i+ 9], 21, -343485551)
  187.  
  188.             a = safe_add(a, olda)
  189.             b = safe_add(b, oldb)
  190.             c = safe_add(c, oldc)
  191.             d = safe_add(d, oldd)
  192.         }
  193.         return [a, b, c, d]
  194.     }
  195.  
  196.     /*
  197.     * Convert an array of little-endian words to a hex string.
  198.     */
  199.     function binl2hex(binarray)
  200.     {
  201.         var hex_tab = "0123456789abcdef"
  202.         var str = ""
  203.         for(var i = 0; i < binarray.length * 4; i++)
  204.         {
  205.             str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
  206.                 hex_tab.charAt((binarray[i>>2] >> ((i%4)*8)) & 0xF)
  207.         }
  208.         return str
  209.     }
  210.  
  211.     /*
  212.     * Convert an array of little-endian words to a base64 encoded string.
  213.     */
  214.     function binl2b64(binarray)
  215.     {
  216.         var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
  217.         var str = ""
  218.         for(var i = 0; i < binarray.length * 32; i += 6)
  219.         {
  220.             str += tab.charAt(((binarray[i>>5] << (i%32)) & 0x3F) |
  221.                       ((binarray[i>>5+1] >> (32-i%32)) & 0x3F))
  222.         }
  223.         return str
  224.     }
  225.  
  226.     /*
  227.     * Convert an 8-bit character string to a sequence of 16-word blocks, stored
  228.     * as an array, and append appropriate padding for MD4/5 calculation.
  229.     * If any of the characters are >255, the high byte is silently ignored.
  230.      */
  231.     function str2binl(str)
  232.     {
  233.         var nblk = ((str.length + 8) >> 6) + 1 // number of 16-word blocks
  234.         var blks = new Array(nblk * 16)
  235.         for(var i = 0; i < nblk * 16; i++) blks[i] = 0
  236.         for(var i = 0; i < str.length; i++)
  237.             blks[i>>2] |= (str.charCodeAt(i) & 0xFF) << ((i%4) * 8)
  238.         blks[i>>2] |= 0x80 << ((i%4) * 8)
  239.         blks[nblk*16-2] = str.length * 8
  240.       return blks
  241.     }
  242.  
  243.     /*
  244.     * Convert a wide-character string to a sequence of 16-word blocks, stored as
  245.     * an array, and append appropriate padding for MD4/5 calculation.
  246.     */
  247.     function strw2binl(str)
  248.     {
  249.         var nblk = ((str.length + 4) >> 5) + 1 // number of 16-word blocks
  250.         var blks = new Array(nblk * 16)
  251.         for(var i = 0; i < nblk * 16; i++) blks[i] = 0
  252.         for(var i = 0; i < str.length; i++)
  253.             blks[i>>1] |= str.charCodeAt(i) << ((i%2) * 16)
  254.         blks[i>>1] |= 0x80 << ((i%2) * 16)
  255.         blks[nblk*16-2] = str.length * 16
  256.         return blks
  257.     }
  258.  
  259.     /*
  260.     * External interface
  261.     */
  262.     function hexMD5 (str) { return binl2hex(coreMD5( str2binl(str))) }
  263.     function hexMD5w(str) { return binl2hex(coreMD5(strw2binl(str))) }
  264.     function b64MD5 (str) { return binl2b64(coreMD5( str2binl(str))) }
  265.     function b64MD5w(str) { return binl2b64(coreMD5(strw2binl(str))) }
  266. </script>
  267.